<?php
    class date{

        public function __construct() {
            $args = func_get_args();
        }

        function monNameENG($monNum){
            switch ($monNum){
                case "01": return "Jan";
                case "02": return "Feb";
                case "03": return "Much";
                case "04": return "Apr";
                case "05": return "May";
                case "06": return "Jun";
                case "07": return "Jul";
                case "08": return "Aug";
                case "09": return "Sep";
                case "10": return "Oct";
                case "11": return "Nov";
                case "12": return "Dec";
            }
        }

        function monNameTH($monNum){
            switch ($monNum){
                case "01": return "มกราคม";
                case "02": return "กุมภาพันธ์";
                case "03": return "มีนาคม";
                case "04": return "เมษายน";
                case "05": return "พฤษภาคม";
                case "06": return "มิถุนายน";
                case "07": return "กรกฎาคม";
                case "08": return "สิงหาคม";
                case "09": return "กันยายน";
                case "10": return "ตุลาคม";
                case "11": return "พฤศจิกายน";
                case "12": return "ธันวาคม";
            }
        }

        function monShortNameTH($monNum){
            switch ($monNum){
                case "01": return "ม.ค.";
                case "02": return "ก.พ.";
                case "03": return "มี.ค.";
                case "04": return "เม.ย.";
                case "05": return "พ.ค.";
                case "06": return "มิ.ย.";
                case "07": return "ก.ค.";
                case "08": return "ส.ค.";
                case "09": return "ก.ย.";
                case "10": return "ต.ค.";
                case "11": return "พ.ย.";
                case "12": return "ธ.ค.";
            }
        }

        function dateEncode($date){
            $temp=explode(" ", $date);
            $date=$temp[0];
            $time=$temp[1];

            $temp=explode("-", $date);
            $yearNum=$temp[0];
            $monNum=$temp[1];
            $dayNum=$temp[2];
            
            $dayNum=(int)$dayNum;

            return $dayNum." ".monNameTH($monNum)." ".$yearNum." ".$time;
        }

        function dateEncodeBE($date){
            $temp=explode(" ", $date);
            $date=$temp[0];
            $time=$temp[1];

            $temp=explode("-", $date);
            $yearNum=$temp[0]+543;
            $monNum=$temp[1];
            $dayNum=$temp[2];
            
            $dayNum=(int)$dayNum;

            return $dayNum." ".$this->monNameTH($monNum)." ".$yearNum." ".$time;
        }

        function dateDisplayToSQL($date){
            $temp=  explode('/', substr($date,0,10));
            return ($temp[2]-543)."-".$temp[1]."-".$temp[0];
        }
    }